package com.tanhua.dubbo.api.Impl;


import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.UserInfoApi;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.domain.UserInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map;


@DubboService
public class UserInfoApiImpl implements UserInfoApi {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findById(Long id) {
        UserInfo userInfo = userInfoMapper.selectById(id);
        return userInfo;
    }

    @Override
    public Map<Long, UserInfo> MakeFriends(List<Long> userIds, UserInfo userInfo) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.in("id",userIds);
        if (userInfo!=null){
            if (userInfo.getAge()!=null){
                 wrapper.lt("age",userInfo.getAge());
            }
            if (!StringUtils.isEmpty(userInfo.getGender())){
                wrapper.eq("gender",userInfo.getGender());
            }
        }

        List<UserInfo> list = userInfoMapper.selectList(wrapper);
        System.out.println(list.size());
        Map<Long,UserInfo> map = CollUtil.fieldValueMap(list,"id");
        return map;
    }
}
